package com.controller;

import com.pojo.ShopComment;
import com.service.ShopCommentService;
import com.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2020/3/20.
 */
@Api(tags = "用户店铺点评API")
@Controller
public class ShopCommentController {
    @Autowired
    private ShopCommentService shopCommentService;
    @ApiOperation(value ="创建点评",notes ="创建点评" )
    @PostMapping("/shopComment")
    @ResponseBody
    public ServerResponse add(ShopComment shopComment){
        // ServerResponse serverResponse =
        //System.out.println("serverResponse:"+serverResponse);
        return shopCommentService.save(shopComment);
    }

    @ApiOperation(value = "根据用户店铺点评的id删除点评",notes ="")
    @DeleteMapping("/shopComment/{id}")
    @ResponseBody
    public ServerResponse del(@PathVariable("id")String id){
        ServerResponse serverResponse = shopCommentService.modifyStatus(Integer.valueOf(id));
        System.out.println("serverResponse:"+serverResponse);
        return serverResponse;
    }

    @ApiOperation(value ="修改用户店铺点评信息",notes ="" )
    @PutMapping("/shopComment")
    @ResponseBody
    public ServerResponse upd(ShopComment shopComment){
        System.out.println(shopComment);
        ServerResponse serverResponse = shopCommentService.modify(shopComment);
        return serverResponse;
    }

    @ApiOperation(value ="根据用户id查询用户店铺点评信息")
    @GetMapping("/shopComment/{id}")
    @ResponseBody
    public ServerResponse findById(@PathVariable("id") String id){
        System.out.println(id);
        ServerResponse serverResponse = shopCommentService.getById(Integer.valueOf(id));
        return serverResponse;
    }

    @ApiOperation(value ="查询用户店铺点评")
    @GetMapping("/shopComment")
    public String  findAll(Model model){
        ServerResponse serverResponse = shopCommentService.getAll();
        model.addAttribute("info",serverResponse.getData());
        return "back/shop/shopComment";
    }
}
